#include "PopUps.h"

bool PopUp::getActive()
{
	return isActive;
}

void PopUp::setActive(bool setting)
{
	isActive = setting;
}

void PopUpControl::init()
{
	theOptions.init();
	theExit.init();
}

void OptionsMenu::init()
{
	isActive = false;

	backdrop.PlaceAt((SCREENHEIGHT/2)+200,(SCREENWIDTH/2)-150,(SCREENHEIGHT/2)-200, (SCREENWIDTH/2)+150);
}

void ExitMenu::init()
{
	isActive = false;

	backdrop.PlaceAt((SCREENHEIGHT/2)+100,(SCREENWIDTH/2)-150,(SCREENHEIGHT/2)-100, (SCREENWIDTH/2)+150);

	yesButton.Initialise((backdrop.GetTopLeft().YValue+125),(backdrop.GetTopLeft().XValue+25), 
		(backdrop.GetBottomRight().YValue-25), (backdrop.GetBottomRight().XValue-165), "Yes");

	noButton.Initialise((backdrop.GetTopLeft().YValue+125),(backdrop.GetTopLeft().XValue+165), 
		(backdrop.GetBottomRight().YValue-25), (backdrop.GetBottomRight().XValue-25), "No");
}

bool PopUp::hovering(MousePointer mouse)
{

	if (backdrop.Intersects(mouse.GetPoint()) == true)
	{
	    return true;
	}
	else
	{
		return false;
	}

}

void PopUp::placing(float top, float left, float bottom, float right)
{
	backdrop.PlaceAt(top, left, bottom, right);
}

void PopUp::placing(Vector2D topLeft, Vector2D bottomRight)
{
	backdrop.PlaceAt(topLeft, bottomRight);
}

void PopUpControl::update(MousePointer mouse)
{
	theOptions.update(mouse);
	theExit.update(mouse);
}

void OptionsMenu::update(MousePointer mouse)
{
	if (!hovering(mouse) && isActive && MyInputs::GetInstance()->IfMouseNewLeftDown())
	{
		isActive = false;
	}
}

void ExitMenu::update(MousePointer mouse)
{
	if (!hovering(mouse) && isActive && MyInputs::GetInstance()->IfMouseNewLeftDown())
	{
		isActive = false;
	}

	yesButton.Update(mouse);
	noButton.Update(mouse);

	if (yesButton.getActive() == true)
	{
		PostQuitMessage(0);
	}

	if(noButton.getActive() == true)
	{
		isActive = false;
	}
}

void PopUp::draw()
{
	MyDrawEngine::GetInstance()->FillRect(backdrop, MyDrawEngine::DARKGREEN);
}

Vector2D PopUp::getTopLeft()
{
	return backdrop.GetTopLeft();
}

Vector2D PopUp::getBottomRight()
{
	return backdrop.GetBottomRight();
}

void PopUpControl::draw()
{
	if (theOptions.getActive())
	{
		theOptions.draw();
	}


	if (theExit.getActive())
	{
		theExit.draw();
	}
}

void OptionsMenu::draw()
{
	MyDrawEngine::GetInstance()->FillRect(backdrop, MyDrawEngine::DARKBLUE);
}

void ExitMenu::draw()
{
	MyDrawEngine::GetInstance()->FillRect(backdrop, MyDrawEngine::DARKGREEN);

	MyDrawEngine::GetInstance()->WriteText((int)backdrop.GetTopLeft().XValue, (int)backdrop.GetTopLeft().YValue,
		"Do you wish to Quit?",MyDrawEngine::BLUE,0);

	yesButton.Draw();
	noButton.Draw();
}

void ExitMenu::exitCheck()
{

}